/**
 * 代理
 */

class Image{
    constructor(filename){
        this.filename = filename
        this.loading()
    }
    loading(){
        console.log(`loading ${this.filename}`)
    }
    display(){
        console.log(`displaying ${this.filename}`)
    }
}

class ImageProxy{
    constructor(filename){
        console.log('not use es6 Proxy')
        this.filename = filename
    }
    display(){
        if(!this.image) this.image = new Image(this.filename)
        console.log('proxy dispaly')
        this.image.display()
    }
}

// let proxy = new ImageProxy('aa.avi')
// proxy.display()
// console.log('------------------')

const IMGP = new Proxy(Image,{
    construct:function(target,args){
        const obj = new Image(args[0])
        return new Proxy(obj,{
            get:function(target,prop,receiver){
                if(prop=='display'){
                    console.log('代理display')
                }
                return Reflect.get(target,prop) 
            }
           
        })
    }
})

const proxyES6 = new IMGP('aa.avi')
proxyES6.display()
